from celery import Celery
def make_celery(app):
    celery = Celery(
        app.import_name,
        backend=app.config['CELERY_RESULT_BACKEND'],
        broker=app.config['CELERY_BROKER_URL']
    )
    celery.conf.update(app.config)

    class ContextTask(celery.Task):
        def __call__(self, *args, **kwargs):
            with app.app_context():
                return self.run(*args, **kwargs)

    celery.Task = ContextTask
    return celery

from app import create_app
flask_app = create_app()
celery = make_celery(flask_app)

# from db import db1
# @celery.task()
# def add_together(a, b):
#     print('123')
#     sql = "insert into test(name) values('234234')"
#     db1.update(sql)
#     return a + b

# @celery.task()
# def send_mail(mail):
#     print("发邮件")
#     return mail